<template>
  <div>
  <van-row gutter="10">
    <van-col span="3" style="padding-top: 5px;padding-left: 20px"><img src="http://img.zhichiwangluo.com/zc_app_default_photo.png" style="width:40px"></van-col>
    <van-col span="2" style="padding-top: 20px;padding-left: 20px" >{{phone}}</van-col>
    <van-col span="15" style="padding-top: 20px;"></van-col>
    <van-col span="2" style="padding-top: 20px;"><van-icon name="arrow" /></van-col>
  </van-row>

    <van-grid gutter="20" column-num="3" :border="false">
      <van-grid-item style="padding-top: 20px;">
        <span>{{score}}</span>
        <span style="color: grey">积分</span>
      </van-grid-item>
      <van-grid-item style="padding-top: 20px">
        <span>{{stored}}</span>
        <span style="color: grey">储值</span>
      </van-grid-item>
      <van-grid-item style="padding-top: 20px">
        <span>{{collect}}</span>
        <span style="color: grey">收藏</span>
      </van-grid-item>

      <van-grid  column-num="5" :border="false" gutter="" >
        <van-grid-item style="padding-top: 20px" @click="getmoney">
          <van-badge :content="paynum">
            <span><van-icon name="balance-pay" /></span><br>
            <span style="font-size: 12px">代付款</span>
          </van-badge>
        </van-grid-item>
        <van-grid-item style="padding-top: 20px">

          <span><van-icon name="cash-on-deliver" /></span>
          <span style="font-size: 12px">待发货</span>
        </van-grid-item>
        <van-grid-item style="padding-top: 20px">
          <span><van-icon name="logistics" /></span>
          <span style="font-size: 12px">待收货</span>
        </van-grid-item>
        <van-grid-item style="padding-top: 20px">
          <span><van-icon name="comment-o" /></span>
          <span style="font-size: 12px">待评价</span>
        </van-grid-item>
        <van-grid-item style="padding-top: 20px;width: 180px">
          <span><van-icon name="phone-o" /></span>
          <span style="font-size: 12px">售后</span>
        </van-grid-item>
      </van-grid>
    </van-grid>



<!--    优惠券-->
    <van-coupon-cell
        style="padding-top: 20px;padding-left: 40px;text-align: left"
        :coupons="coupons"
        :chosen-coupon="chosenCoupon"
        @click="coupon"
        icon="coupon-o"
    />
    <!-- 优惠券列表 -->
    <van-popup
        v-model="couponBoolean"
        round
        position="bottom"
        style="height: 90%; padding-top: 4px;"
    >
      <van-coupon-list
          :coupons="coupons"
          :chosen-coupon="chosenCoupon"
          :disabled-coupons="disabledCoupons"
          @change="onChange"
          @exchange="onExchange"
      />
    </van-popup>


<!--    收货地址-->
    <van-cell
        style="padding-top: 20px;padding-left: 40px;text-align: left"
        @click="addressBoolean = true"
        title="收货地址"
        icon="location-o"
    />
    <van-popup
        v-model="addressBoolean"
        round
        position="bottom"
        style="height: 90%; padding-top: 4px;"
    >
      <!--    收货地址-->
      <van-address-list
          v-model="chosenAddressId"
          :list="list"
          @add="onAdd"
          @edit="onEdit"
      />
    </van-popup>
    <div style="margin: 30px;">
      <van-button round block type="primary" @click=" tzregister()" >{{pian}}</van-button>
    </div>




  </div>
</template>

<script>

export default {
  name: "MyView",

  data() {
    return {
      score: 0,
      level: 0,
      stored: 0,
      collect: 0,
      paynum:0,
      phone: "",
      pian: "注销登录",

      token:this.$store.state.token,
      //跳出层  默认为关  点击时显示 true  关闭时 false
      couponBoolean:false,

      addressBoolean:false,

      //选择优惠券索引 -1 默认为不选
      chosenCoupon: -1,
      //可用优惠券列表参数
      coupons: [],
      //不可用优惠券列表参数
      disabledCoupons: [],

      couponinfodto:{
        oid:1,
        coupid:1
      },

      //地址
      chosenAddressId: '1',
      list: [
        {
          id: '',
          name: '',
          tel: '',
          address: '',
          isDefault: true,
        },
      ],
    }


  },
  mounted() {
    this.axios.get("/api/address/my.do").then(res => {
      this.list=res.data.data
    })
   if(this.$store.state.token==0){
     this.$router.push("/m")
   }else {
     console.log(this.$store.state.token)
     this.axios.get("/api/user/selectone.do").then(res=>{
       this.phone=res.data.data.phone;
       this.user = res.data.data;
     })
     this.axios.get("/api/userlevel/select.do").then(res=>{
       this.score=res.data.data.score
       this.level = res.data.data.levelmsg
     })
     this.axios.get("/api/order/ordernum.do").then(res=>{
       this.paynum=res.data.data
       console.log(this.paynum)
     })
   }
  },

  methods: {
    onChange(index) {
      this.couponBoolean = false;
      this.chosenCoupon = index;
      this.$toast("选择优惠券");
      this.axios.get("/api/couponInfo/selectByUid?token=" + this.token).then(res => {
        this.couponinfodto.coupid = res.data.data[this.chosenCoupon].coupid;
        this.axios.get("/api/couponInfo/discountPrice?price=" + this.couponinfodto.price + "&coupid=" + this.couponinfodto.coupid).then(res => {
          if(res.data.code=200){
            console.log(res.data.data);
          }else{
            this.$toast("您的金额不够使用优惠券！！！");
          }
        })

      })
    },
    getmoney(){
      console.log("-------------")
      this.$router.push("/queryorder")
    },
    onExchange(code) {
      this.coupons.push(this.coupons);
    },
    onAdd() {
      this.$toast('新增地址');
    },
    onEdit(item, index) {
      this.$toast('编辑地址:' + index);
    },
    tzregister() {
      this.axios.get("/api/user/selectone.do").then(res => {
        console.log(res.data.data)
        if (res.data.code = 200) {
          this.$store.commit("setToken", 0);
          this.$router.push("/m");
        } else {
          this.$toast(res.data.msg);
        }
      })
    },
    coupon() {
      this.coupons = [];
      this.couponBoolean = true;
      // this.axios.get("/api/couponInfo/selectByUid?token=" + this.token).then(res => {
      //   if (res.data.code == 200) {
      var a = {}
      // for (var i in res.data.data) {
      this.axios.get("/api/coupon/selectById?token="+ this.token).then(res => {
        console.log(res.data.data)
        if (res.data.code = 200) {
          for (var i in res.data.data){
            a = {}
            var ctime = res.data.data[i].ctime;
            a.condition = res.data.data[i].info;
            a.reason = '';
            a.value = res.data.data[i].discountprice * 100;
            a.name = '优惠券名称';
            a.startAt = new Date(ctime).getTime();
            a.endAt = new Date(ctime).getTime() + 60000000;
            a.valueDesc = res.data.data[i].discountprice;
            a.unitDesc = '元';
            this.coupons.push(a)
          }
        }
      })

    }



  }
}


</script>

<style scoped>

</style>